﻿using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Navigation;
using AuchanScan.Models;
using AuchanScan.ViewModels;
using Microsoft.Phone.Controls;

namespace AuchanScan.Views
{
    public partial class TrophyPage : PhoneApplicationPage
    {
        public TrophyPage()
        {
            InitializeComponent();
            this.Loaded += (s, e) =>
            {
                lstTrophySimulation.Visibility = System.Windows.Visibility.Collapsed;
                lstCurrentTrophies.Visibility = System.Windows.Visibility.Visible;
            };
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.Keys.Count > 0 && NavigationContext.QueryString.ContainsKey("a"))
            {
                if (e.NavigationMode != NavigationMode.Back)
                {
                    var vm = DataContext as TrophyViewModel;
                    if (vm != null)
                    {
                        ObservableCollection<Achat> courses = ViewModelLocator.MainViewModelStatic.Datas.Courses;
                        if (courses != null && courses.Count > 0)
                        {
                            vm.Simulate(courses.ToList());
                            lstCurrentTrophies.Visibility = System.Windows.Visibility.Collapsed;
                            lstTrophySimulation.Visibility = System.Windows.Visibility.Visible;
                        }
                    }
                }
            }
        }
    }
}